//
//  RBSearchGoodsCell.m
//  zhongzhenglu
//
//  Created by XL on 2022/7/12.
//

#import "RBSearchGoodsCell.h"
#import <Masonry.h>
#import "RBTagContainerView.h"
#import "RanTool.h"
#import "RBDefine.h"
#import "UIView+RBAdd.h"
#import "RBThemeConfig.h"
#import <UIColor+YYAdd.h>
#import <UIView+YYAdd.h>
#import "RBSearchGoodsProgressView.h"

@interface RBSearchGoodsCell()

@property(nonatomic, strong)UIImageView *imgView;
@property(nonatomic, strong)UILabel *flagL;

@property(nonatomic, strong)UIView *rightContainer;
@property(nonatomic, strong)UILabel *nameL;
@property(nonatomic, strong)RBSearchGoodsProgressView *progressView;
@property(nonatomic, strong)RBTagContainerView *tagContainer;
@property(nonatomic, strong)UILabel *priceL;
@property(nonatomic, strong)UILabel *saleCountL;

@end

@implementation RBSearchGoodsCell

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    
    return self;
}

- (void)setCellModel:(RBCellModel *)cellModel {/*
    //model
    RBSearchResultModel *model = cellModel.cellData;
    //图片
    [self.imgView setImageWithUrl:model.picurl placeHolder:nil];
    //标签
    self.flagL.backgroundColor = [UIColor colorWithHexString:@"#F37152"];
    self.flagL.text = @"好物推荐";
    //
    [self.rightContainer view_clear];
    //商品名称
    [self.rightContainer view_addView:self.nameL withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:0 bottom:0 left:0 right:0 centerX:0];
    self.nameL.attributedText = [RanTool attributeStringMaker:^(NSMutableArray *maker) {
        [maker addAttributeStringWithFont:[UIFont systemFontOfSize:Zoom(15)] color:[RBThemeConfig textBlackColor] string:model.good_name lineSpacing:Zoom(7)];
    }];
    //
    
//    {
//        self.flagL.backgroundColor = [UIColor colorWithHexString:@"#E83922"];
//        self.flagL.text = @"秒杀";
//    }
    
    
    
    
//    if (arc4random_uniform(4))
//    {
//        self.progressView.percent = arc4random_uniform(6)/5.0;
//        [self.rightContainer view_addView:self.progressView withHeight:self.progressView.itemH width:self.progressView.itemW top:Zoom(12) bottom:0 left:0 right:CGFLOAT_MIN centerX:0];
//    }
    
//    {
//        int count = arc4random_uniform(3)*2;
//        if (count)
//        {
//            NSMutableArray *arrayM = NSMutableArray.array;
//            for (NSInteger i = 0; i < count; i++)
//            {
//                [arrayM addObject:[self tagViewWithTitle:@"清洗消毒机"]];
//            }
//            [self.tagContainer addTagViews:arrayM];
//            [self.rightContainer view_addView:self.tagContainer withHeight:self.tagContainer.calulatedHeight width:CGFLOAT_MIN top:Zoom(10) bottom:0 left:0 right:0 centerX:0];
//        }
//    }
    //价格
    [self.rightContainer view_addView:self.priceL withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:Zoom(17) bottom:0 left:0 right:0 centerX:0];
    self.priceL.attributedText = [RanTool attributeStringMaker:^(NSMutableArray *maker) {
        [maker addAttributeStringWithFont:[UIFont boldSystemFontOfSize:Zoom(11)] color:[UIColor colorWithHexString:@"#F04D27"] string:@"￥"];
        [maker addAttributeStringWithFont:[UIFont boldSystemFontOfSize:Zoom(15)] color:[UIColor colorWithHexString:@"#F04D27"] string:model.price];
    }];
    //销量
    [self.rightContainer view_addView:self.saleCountL withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:Zoom(12) bottom:0 left:0 right:0 centerX:0];
    self.saleCountL.attributedText = [RanTool attributeStringMaker:^(NSMutableArray *maker) {
        [maker addAttributeStringWithFont:[UIFont systemFontOfSize:Zoom(12)] color:[RBThemeConfig textGrayColor] string:({
            NSString *text = @"2万+评论  3000+销量";
            
//            text = [NSString stringWithFormat:@"2万+评论  %@销量", model.];
            text;
        })];
    }];
//    if (arc4random_uniform(2))
//    {
//
//    }
//    else
//    {
//        self.saleCountL.attributedText = [RanTool attributeStringMaker:^(NSMutableArray *maker) {
//            [maker addAttributeStringWithFont:[UIFont systemFontOfSize:Zoom(12)] color:[RBThemeConfig textGrayColor] string:@"¥400" lineSpacing:0 througnLineHeight:1 throughLineColor:[RBThemeConfig textGrayColor]];
//            [maker addAttributeStringWithFont:[UIFont systemFontOfSize:Zoom(12)] color:[RBThemeConfig textGrayColor] string:@" 剩余200"];
//        }];
//    }*/
}

#pragma mark - Getter

- (UIImageView *)imgView
{
    if (!_imgView)
    {
        self.imgView = ({
            UIImageView *view = UIImageView.new;
            view.image = [UIImage imageNamed:@"b1.jpg"];
            view.contentMode = UIViewContentModeScaleAspectFill;
            [view rbSetCornerRadius:Zoom(4)];
            [self.contentView addSubview:view];
            [view mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(Zoom(13));
                make.top.mas_equalTo(Zoom(12));
                make.width.height.mas_equalTo(Zoom(97));
            }];
            view;
        });
    }
    return _imgView;
}

- (UILabel *)flagL
{
    if (!_flagL)
    {
        self.flagL = ({
            UILabel *view = UILabel.new;
            view.size = CGSizeMake(Zoom(44), Zoom(18));
            [view setRounderWithRectCorner:UIRectCornerTopRight | UIRectCornerBottomLeft radius:Zoom(4)];
            view.backgroundColor = [UIColor colorWithHexString:@"#F37152"];
            view.font = [UIFont systemFontOfSize:Zoom(9)];
            view.textColor = UIColor.whiteColor;
            view.textAlignment = NSTextAlignmentCenter;
            view.text = @"好物推荐";
            [self.contentView addSubview:view];
            [view mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.right.mas_equalTo(self.imgView);
                make.size.mas_offset(view.size);
            }];
            view;
        });
    }
    return _flagL;
}

- (UIView *)rightContainer
{
    if (!_rightContainer)
    {
        self.rightContainer = ({
            UIView *view = UIView.new;
            [self.contentView addSubview:view];
            [view mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.mas_equalTo(Zoom(12));
                make.right.mas_equalTo(Zoom(-13));
                make.bottom.mas_equalTo(-Zoom(12));
                make.left.mas_equalTo(self.imgView.mas_right).offset(Zoom(14));
            }];
            view;
        });
    }
    return _rightContainer;
}

- (UILabel *)nameL
{
    if (!_nameL)
    {
        self.nameL = ({
            UILabel *view = UILabel.new;
            view.numberOfLines = 2;
            view;
        });
    }
    return _nameL;
}

- (RBSearchGoodsProgressView *)progressView
{
    if (!_progressView)
    {
        self.progressView = ({
            RBSearchGoodsProgressView *view = RBSearchGoodsProgressView.new;
            view.itemW = Zoom(173);
            view.itemH = Zoom(14);
            view;
        });
    }
    return _progressView;
}

- (RBTagContainerView *)tagContainer
{
    if (!_tagContainer)
    {
        self.tagContainer = ({
            RBTagContainerView *view = RBTagContainerView.new;
            view.constraintWidth = Zoom(230);
            view.hMargin = Zoom(10);
            view.vMargin = Zoom(10);
            view;
        });
    }
    return _tagContainer;;
}

- (UIView *)tagViewWithTitle: (NSString *)title
{
    UIView *view = UIView.new;
    view.backgroundColor = [UIColor colorWithHexString:@"#F4F4F4"];
    view.height = Zoom(18);
    [view rbSetCornerRadius:Zoom(9)];
    CGFloat padding = Zoom(7);
    
    UILabel *textL = UILabel.new;
    textL.text = title;
    textL.font = [UIFont systemFontOfSize:Zoom(12)];
    textL.textColor = [RBThemeConfig textGrayColor];
    [view addSubview:textL];
    [textL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_equalTo(0);
        make.left.mas_equalTo(padding);
        make.right.mas_equalTo(-padding);
    }];
    
    view.width = padding * 2 + [RanTool sizeWithText:textL.text consSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX) font:textL.font].width + 2;
    return view;
}

- (UILabel *)priceL
{
    if (!_priceL)
    {
        self.priceL = ({
            UILabel *view = UILabel.new;
            view;
        });
    }
    return _priceL;
}

- (UILabel *)saleCountL
{
    if (!_saleCountL)
    {
        self.saleCountL = ({
            UILabel *view = UILabel.new;
            view;
        });
    }
    return _saleCountL;
}

@end
